package com.ruoyi.utils;

import com.ruoyi.erpconfig.domain.YyCompany;
import com.ruoyi.erpconfig.mapper.JdCompanyMapper;
import com.ruoyi.erpconfig.mapper.YyCompanyMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.*;
import java.util.Properties;

public  class ERPConfigUtil {

    @Autowired
    private JdCompanyMapper jdCompanyMapper;

    @Autowired
    private YyCompanyMapper yyCompanyMapper;
    //通过用友公司erp的id，将数据库中的配置信息配置到后台
    public static void main(String[] args) throws IOException {
        ERPConfigUtil  erpConfigUtil =new ERPConfigUtil();
//        YyCompany yyCompany = new YyCompany();
//        yyCompany.setYyCompanyId(new Long(1));
//        yyCompany.setYyCompanyAppkey("opac530a7eabe24d6c5");
//        yyCompany.setYyCompanyAppsecret("a943ece675504167935ec8f120b8bfcd");
//        yyCompany.setYyCompanyFromaccount("wanxing");
//        yyCompany.setYyCompanyToaccount("test_wanxing");
//        erpConfigUtil.yyConfig(yyCompany);
        File file = new File("\ruoyi-admin\\src\\main\\resources\\config.properties");

        System.out.println(file.exists());
        erpConfigUtil.config();



    }

    public void config() throws IOException {
        InputStream in = this.getClass().getResourceAsStream("/config.properties");
        Properties pro = new Properties();
        pro.setProperty("api_url_token_get", "https://api.yonyouup.com/system/token?from_account={from_account}&app_key={app_key}&app_secret={app_secret}");
        pro.setProperty("api_url_trade_get", "https://api.yonyouup.com/system/tradeid?from_account={from_account}&app_key={app_key}&token={token}");
        pro.setProperty("api_url_orderstatus_get", "https://api.yonyouup.com/orderstatus/get?from_account={from_account}&to_account={to_account}&app_key={app_key}&token={token}");
        pro.setProperty("api_url_result_get ", "https://api.yonyouup.com/result?requestid={requestid}");
        pro.setProperty("baseURL ", "https://api.yonyouup.com/api/");
        String path = this.getClass().getClassLoader().getResource("config.properties").getPath();
        System.out.println(path);
        pro.store(new FileOutputStream(path),"用友公司配置文件");
    }

    public void yyConfig(YyCompany yyCompany) throws FileNotFoundException {

        try{
            String path = this.getClass().getClassLoader().getResource("").getPath();
            path += "config.properties";
            File file = new File(path);
            Properties pro = new Properties();
            if (!file.exists()) {

                file.createNewFile();
                System.out.println("文件已创建");

            } else {
                System.out.println("文件已存在");
            }
            pro.setProperty("from_account", yyCompany.getYyCompanyFromaccount());
            pro.setProperty("to_account", yyCompany.getYyCompanyToaccount());
            pro.setProperty("app_key", yyCompany.getYyCompanyAppkey());
            pro.setProperty("app_secret", yyCompany.getYyCompanyAppsecret());
            pro.setProperty("api_url_token_get", "https://api.yonyouup.com/system/token?from_account={from_account}&app_key={app_key}&app_secret={app_secret}");
            pro.setProperty("api_url_trade_get", "https://api.yonyouup.com/system/tradeid?from_account={from_account}&app_key={app_key}&token={token}");
            pro.setProperty("api_url_orderstatus_get", "https://api.yonyouup.com/orderstatus/get?from_account={from_account}&to_account={to_account}&app_key={app_key}&token={token}");
            pro.setProperty("api_url_result_get ", "https://api.yonyouup.com/result?requestid={requestid}");
            pro.setProperty("baseURL ", "https://api.yonyouup.com/api/");
            pro.store(new FileOutputStream(path),"用友公司配置文件");


            } catch (IOException e) {
            e.printStackTrace();
        }





    }

    //通过金蝶公司erp的id，将数据库中的配置信息配置到后台
    public   void jdConfig(int id){

    }
}
